home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / xsharp22 / readme < prev    next >
Text File  |  1994-09-18  |  17KB  |  341 lines

  1. This is the source for the X-Sharp 3-D animation package, version 22,
  2. as presented in the Graphics Programming column in Dr. Dobb's
  3. Journal, as of the October 1992 issue, and in the Pushing the
  4. Envelope column in PC Techniques magazine, as of the August 1994
  5. issue.  Faster Mode X texture-mapped polygons (in the neighborhood of
  6. 2-5 times faster, depending on the hardware and the texture mapping
  7. being performed) have been added since the last version, version 21;
  8. the texture mapping is done along screen columns rather than rows, in
  9. order to avoid changing the Map Mask on a per-pixel basis, as was
  10. previously the case.  In addition, the texture mapping inner loop has
  11. been tightened a great deal.  Thanks to Chris Hecker
  12. (checker@bix.com) and to John Miles of NonLinear Arts for their
  13. input, encouragement, and inspiration regarding the new texture
  14. mapping (kicked me right in the fanny, they did, and didn't let me
  15. quit until it was maxed out; see the Pushing the Envelope column in
  16. the August 1994 PC Techniques for details).  The code has been tested
  17. with Borland C++ 3.0 and TASM 3.0.  To make the X-Sharp demo program
  18. DEMO1, run K1.BAT.  (DEMO1.EXE is also in the ZIP file.)  When you run
  19. DEMO1, I suggest you use the '0' key to turn on a spotlight, then use
  20. the 'S' key to speed up the rotation and switch between X, Y, and Z
  21. as the axis of rotation. Also keep an eye peeled for "ursanauts"!
  22.  
  23. Unpack this archive with PKUNZIP -d; the ball generation code belongs
  24. in the .\BALL subdirectory, and, because it has some of the same
  25. filenames as the main directory, problems will result without -d.
  26.  
  27. Files in this archive:
  28.  
  29. APPROT.C     - appends rotations in X, Y, and Z
  30. BALL         - subdirectory containing ball-generation code; see below
  31. BALVERT0.INC - include file generated by .\BALL\GENBALL that defines
  32.                 ball-shaped object
  33. COLOR.C      - RGB space -> adapter palette space color mapping, color
  34.                intensity adjustment
  35. COSTABLE.INC - include file for fixed-point cosines between 0 and 90 degrees,
  36.                 generated by GENCOS
  37. DEMO1.C      - X-Sharp demo program
  38. DEMO1.EXE    - demo program built by running K1.BAT (also in ZIP file)
  39. DRAW.ASM     - draws the scanned-out pixels of a convex polygon in mode X
  40. DRAWPOBJ.C   - draws a polygon-based object
  41. DRAWTEX.ASM  - assembly-language implementation of inner-loop texture drawing
  42. DRAWTEXP.C   - draws a texture-mapped polygon
  43. FILLCNVX.C   - fills a convex polygon
  44. FILLRECT.ASM - fills a rectangle with a solid color in mode X
  45. FIXED.ASM    - fixed point arithmetic routines
  46. GAMMA        - subdirectory containing gamma correction table generation
  47.                 program
  48. GENCOS.C     - generates cosine table for fixed-point look-up
  49. GLOBALS.C    - global variables
  50. INITBALL.C   - initializes the ball-shaped object
  51. INITFIX.C    - initializes fixed-point data
  52. INITLIGH.C   - sets up initial illumination (ambient and diffuse lighting)
  53. INITPAL.C    - sets up the adapter color palette
  54. K1.BAT       - remakes X-Sharp, producing demo program DEMO1
  55. LIGHTING.C   - illumination control
  56. LINKRESP     - TLINK response file
  57. MAKEFILE     - Borland Make makefile
  58. MODE.ASM     - initializes the screen to mode X (320x240, 256 colors)
  59. MOVEOBJ.C    - updates the position and orientation of polygon-based objects
  60. OLIST.C      - object list initialization, handling, and sorting
  61. POLYGON.H    - polygon & 3-D header file
  62. README       - this file
  63. SCAN.ASM     - scans out an edge of a convex polygon
  64. SHOWPAGE.ASM - selects the video page that's visible
  65. TURBOC.CFG   - Borland C++ 3.0 configuration file.  Uses 3.0-specific
  66.                 options, which must be changed for 2.0 and earlier
  67. XFPROJ.C     - transforms and projects polygon-based objects
  68. XSHARP22     - ID file for the X-Sharp version
  69.  
  70. The subdirectory .\BALL contains the source code and executable for
  71. the program GENBALL, which creates the vertex and face lists for a
  72. ball made from rectangular faces (BALVERT0.INC was created by GENBALL).
  73. Remake GENBALL by running K.BAT in the .\BALL directory.  See the
  74. 12/29/91 log entry for details.
  75.  
  76. Note that TURBOC.CFG specifies full optimization for BC++ 3.0 with
  77. -O2 -Oa.  You will have to change these switches for earlier versions
  78. of BC++.
  79.  
  80. Note that this code uses 386-specific instructions unless USE386 is
  81. set to 0 in FIXED.ASM.  With USE386 set to 0, the demo will run on an 8088
  82. or 286, but performance is poor except on a very fast 286.  Performance is
  83. quite good on a 20 MHz 386, and very good--30 to 60 frames per second--on
  84. a 33 MHz 486.
  85.  
  86. Comments and questions may be directed to me in the following ways:
  87.  
  88. Internet:  mabrash@bix.com or mabrash@mcimail.com
  89. U.S. Mail (21801 NE 22nd Street, Redmond, WA 98053)
  90.  
  91. I will do my best to respond, time permitting.  No guarantees.
  92.  
  93. Bix is the best way to get hold of me.
  94.  
  95. This material may be used freely; it is provided free of charge, as
  96. are responses to questions and comments, within reason.  Should the
  97. spirit move you, a contribution to the Vermont Assocation for the
  98. Blind and Visually Impaired, sent care of Dr. Dobb's Journal, myself,
  99. or directly to VABVI, would be appreciated, and would motivate me to
  100. keep enhancing X-Sharp.  Please make checks payable to the Vermont
  101. Association for the Blind and Visually Impaired.
  102.  
  103. Vermont Association for the Blind and Visually Impaired
  104. 37 Elmwood Avenue
  105. Burlington, VT 05401
  106.  
  107. Dr. Dobb's Journal
  108. 411 Borel Avenue, Suite 100
  109. San Mateo, CA 94403-3522
  110.  
  111. *****************************************************************
  112. * This code is provided as-is, with no warranties of any sort.  *
  113. * So far as I know, it works fine, but use it at your own risk! *
  114. *****************************************************************
  115.  
  116. --Michael Abrash  9/18/94
  117.  
  118.  
  119.                      ******************
  120.                      * Log of changes *
  121.                      ******************
  122.  
  123. **********************************************************************
  124. Begin entry for 9/18/94
  125.  
  126. ----------
  127. Changed DRAWTEX.ASM and DRAWTEXP.ASM to do texture mapping along
  128. vertical columns rather than horizontal rows, so that the Map Mask
  129. only has to be set once per column.  Squeezed a bunch of cycles out
  130. of the inner texture-mapping loop.  Also changed all jumps in
  131. assembly code that has .386 set to have "short" prefix, because the
  132. assembler was sticking in 2 NOPs otherwise.
  133.  
  134. **********************************************************************
  135. Begin entry for 7/5/92
  136.  
  137. ----------
  138. Implemented single-scan-line texture-map drawing (inner loop for drawing
  139. texture-mapped polygons) in reasonably tight assembly language in
  140. DRAWTEX.ASM.  Also changed texture-map algorithm to half-include all
  141. texture-map pixels that map to edges, so that textures will remain
  142. reasonably symmetric as the destination polygons to which they are
  143. mapped rotate.
  144.  
  145. **********************************************************************
  146. Begin entry for 6/10/92
  147.  
  148. ----------
  149. Added texture-mapped polygons, drawn by DRAWTEXP.ASM.  Implementation
  150. is currently in C and not particularly fast, but does work pretty
  151. well.  There are rough edges remaining in which source pixels get
  152. mapped to which destination pixels; right now, things follow the
  153. standard polygon edge rules, which hold that pixels exactly on the
  154. right and bottom edges aren't drawn.  This causes slightly different
  155. portions of the image to be mapped in depending on the orientation of
  156. the destination polygon.  Also, there are some problems resulting from
  157. the use of truncated integers as screen coordinates.  Still, the results
  158. look good and don't miss any destination pixels, so the code is
  159. certainly usable right now.
  160.  
  161. **********************************************************************
  162. Begin entry for 5/2/92
  163.  
  164. ----------
  165. Altered DRAW.ASM to draw as much as possible a word at a time.
  166.  
  167. **********************************************************************
  168. Begin entry for 4/3/92
  169.  
  170. ----------
  171. Implemented support for 8088 and 286 fixed-point math in FIXED.ASM.
  172. Previously, only 386 and up processors were supported.  See comments in
  173. FIXED.ASM for limitations of the 8088/286 version of FixedDiv().
  174.  
  175. ----------
  176. Altered the polygon Face structure so that the first vertex in the vertex
  177. list (VertNums) for any shaded polygon must now be the endpoint of a unit
  178. normal vector that has the second vertex in the vertex list as the
  179. startpoint. This unit vector is then transformed along with the rest of the
  180. polygon, and is used for calculating diffuse shading.  Note that the first
  181. vertex in the polygon's vertex list is *not* a vertex of the actual polygon,
  182. just the endpoint of the unit normal.  However, the second vertex in the
  183. polygon's vertex list *is* a vertex of the actual polygon.  Look at
  184. GENBALL.C, in subdirectory BALL, to see an example of the creation of
  185. polygon vertices and face lists.  Note that NumVerts in the polygon
  186. Face structure does not count the first (unit-normal endpoint) vertex.
  187.  
  188. Changed XFPROJ.C so that unit normal endpoints are only transformed into
  189. view space, not into screen space or screen coordinates.  Since the unit
  190. normals are useless once they're transformed into screen space (they're not
  191. normals at that point, because perspective transformation doesn't preserve
  192. angles), there's no reason to waste time transforming them into screen space,
  193. so we don't.  This requires that the unit normal endpoints *always* be the
  194. last endpoints in an object's vertex list, and that NumRealVerts (a new entry
  195. in the PObject structure) now specifies how many real polgyon vertices there
  196. are (that is, how many vertices there are excluding unit normal endpoints),
  197. so that XFPROJ.C knows to only transform NumRealVerts vertices into screen
  198. space.
  199.  
  200. ----------
  201. Implemented a full-color color model.  Polygon colors are now described as
  202. RGB triples, with 8 bits of resolution for each color component.  These
  203. colors are stored in ModelColor structures.  There is a ModelColor entry
  204. in each polygon's Face structure.  There is also a ColorIndex entry,
  205. specifying a direct color index to be used for drawing the polygon; this is
  206. equivalent to the previous style of drawing polygons, and is used only for
  207. unshaded (unilluminated) polygons.  Of course, the VGA doesn't have 24 bits
  208. per pixel.  InitializePalette(), in INITPAL.C, sets up the palette however
  209. you'd like; currently with 64 levels each of pure red, green, and blue, and
  210. 2 levels each of red, green, and blue for mixing.  This is a good model for
  211. displaying pure primary colors, but suffers severe color quantization for
  212. mixed colors.  ModelColorToColorIndex(), in COLOR.C, maps colors from the
  213. model 24-bit RGB color space into the actual available palette.  Note that
  214. InitializePalette() and ModelColorToColorIndex() are designed as replaceable
  215. modules, so any desired adapter-specific color mapping can easily be
  216. implemented; the rest of X-Sharp works in 24-bit RGB space.
  217.  
  218. ----------
  219. Implemented two types of shading:  ambient and diffuse (Lambert).  Ambient
  220. shading is nondirectional illumination, basically background light.
  221. Diffuse shading is directed illumination, treated as illumination by
  222. infinitely distant spotlights in X-Sharp and defined by a unit vector for
  223. direction and an RGB intensity for illumination level.  Added the ShadingType
  224. field to the polygon Face structure to select either, both, or neither of
  225. AMBIENT_SHADING and DIFFUSE_SHADING.  Modified DRAWPOBJ.C to perform the
  226. selected shading, using the unit normal of each polygon (discussed above),
  227. the RGB color of the polygon, the unit vector of each spotlight, and the
  228. intensity of each spotlight to calculate the shading for each polygon.
  229. Created the ModelIntensity structure to describe ambient and spotlight
  230. intensity levels as fixed-point RGB values.  Added a variety of functions
  231. to control illumination in LIGHTING.C.  Added InitializeLighting() to set
  232. up the initial lighting state.
  233.  
  234. ----------
  235. Implemented main program DEMO1.C, which displays a shaded, faceted ball with
  236. ambient lighting and three user-controllable spotlights, as well as
  237. user-controllable positioning, as the current X-Sharp demo program.  This
  238. replaces the previous demo program XS.C.
  239.  
  240. ----------
  241. Modified INITBALL.C to support the new polygon format, new color model, and
  242. shading.  The ball now has 71 faces that are illuminated with both diffuse
  243. and ambient shading, and 1 unshaded face that always has a constant color,
  244. yellow.
  245.  
  246. ----------
  247. Eliminated INITCUBE.C.
  248.  
  249. ----------
  250. Renamed MOVEPOLY.C to MOVEOBJ.C and changed function RotateAndMovePObject()
  251. to handle movement events set in main() and renamed the function to
  252. RotateAndMoveBall().
  253.  
  254. ----------
  255. Modified .\BALL\GENBALL.C to generate the new polygon format, with the
  256. first vertex for each face now the endpoint of a unit normal coming out of
  257. the second vertex.  The first vertex is not a part of the polygon, but is
  258. only used to determine the polygon's orientation.  See the above entry on
  259. the polygon Face structure for details.
  260.  
  261. ----------
  262. Other, minor changes such as the addition of some macros have been made.  I'm
  263. afraid I don't remember 'em all...
  264.  
  265. End entry for 4/3/92
  266. **********************************************************************
  267. Begin entry for 1/5/92
  268.  
  269. ----------
  270. Altered ConcatXforms to add in the translation element from matrix #1
  271. only when multiplying by the fourth column of matrix #2, because only
  272. the fourth column has a 1 at the bottom.  This fixes a bug in earlier
  273. versions that showed up when a world->view transformation involving
  274. translation was used.
  275.  
  276. ----------
  277. Removed setting of non-existent element XformToWorld[3][3] in INITCUBE.C
  278. and INITBALL.C.
  279.  
  280. End entry for 1/5/92
  281. **********************************************************************
  282. Begin entry for 12/29/91
  283.  
  284. ----------
  285. Converted XformVec and ConcatXforms to assembly language, reducing
  286. transformation and concatenation time to 5% or less of total time.
  287.  
  288. ----------
  289. Converted sin() and cos() calls to calls to the assembly language
  290. function CosSin(), which performs a table look-up.  Changed angle
  291. representations from radians to tenths of degrees to facilitate table
  292. look-up and to maximize accuracy.
  293.  
  294. ----------
  295. Put all the assembly language functions in fixed.asm, replacing
  296. l4.c and l9.asm.
  297.  
  298. ----------
  299. Deleted one cube from the animation, and substituted a ball.  The
  300. ball has a radius of 25, slightly larger than the cube it replaces.
  301. It has 6 bands of 12 facets each, for a total of 72 faces,
  302. approximately doubling the number of polygons in the animation, and
  303. has 62 vertices, increasing the number of vertices by more than 50%.
  304. Added INITBALL.C to initialize the ball, and added a call to
  305. InitializeBalls() to create the ball in main().  Only one ball is
  306. created, but more balls could easily be added, and the size of and
  307. number of bands in the ball(s) could easily be changed.
  308.  
  309. The program GENBALL, in .\BALL, generates all vertex and face info
  310. for a generic ball (it doesn't generate the color info, which varies
  311. from instance to instance).  The number of bands of faces and the
  312. size of the ball are prompted for when GENBALL is run.  The output of
  313. GENBALL with 6 bands and a radius of 25 is in BALVERT0.INC, and is
  314. included in INITBALL.C, which initializes a ball for use in the
  315. animation program.  To change the size, just regenerate BALVERT0.INC
  316. by running GENBALL with bands = 6 and the desired radius.  To change
  317. the number of bands, run GENBALL with the desired number of bands and
  318. radius, and then change the Colors array in INITBALL.C to have one
  319. color entry for each face in the new ball. (The number of faces is
  320. shown as a define at the top of the output file from GENBALL.) 
  321. Additional balls may be added by changing NUM_BALLS, and by adding a
  322. new entry to each array at the top of GENBALL.C.
  323.  
  324. ----------
  325. Changed object list from an array to a linked list that is sorted
  326. in back-to-front order after each set of moves, so drawing the list
  327. in order performs proper hiding of objects.
  328.  
  329. ----------
  330. Renamed source files more meaningfully, and renamed executable XS.EXE.
  331.  
  332. ----------
  333. Added a center (0,0,0) point to each object, which is transformed into
  334. view space each time the object is transformed.  This is used for
  335. Z-sorting objects for drawing precedence purposes, and can also be
  336. used for collision detection and the like.
  337.  
  338. End entry for 12/29/91
  339. **********************************************************************
  340.  
  341.